/**
 * Created with IntelliJ IDEA.
 * Description:thread匿名内部类
 * User: lenovo
 * Date: 2022-09-04
 * Time: 16:29
 */
public class Demo3 {
    public static void main(String[] args) {
        //Thread匿名内部类
        Thread thread = new Thread(){//父类引用引用子类对象,向上转型
            @Override
            public void run() {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1_000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };//匿名内部类 实例化了Thread的子类对象并且重写了run方法
        thread.start();

        while (true){
            System.out.println("hello main");
            try {
                Thread.sleep(1_000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
